package com.itheima.train.manager.search.controller;

import com.itheima.train.manager.domain.TbRidingPlanDate;
import com.itheima.train.manager.search.service.RidingPlanDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping(value = "/ridingPlan")
@CrossOrigin(origins = "http://www.trainmanager.com")
public class RidingPlanDateController {

    @Autowired
    private RidingPlanDateService ridingPlanDateService ;

    /**
     * 前端用户在进行搜索的时候需要传递一些参数：开始站点名称 , 到的站点名称 ， 乘车日期，列车类型
     * 并且在传递这些参数的时候，数据的格式都是json
     * @return
     */
    @RequestMapping(value = "/queryByCondition" , method = RequestMethod.POST)
    public List<TbRidingPlanDate> queryByCondition(@RequestBody TbRidingPlanDate tbRidingPlanDate) {

        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 调用service的方法，完成搜索，把结果进行返回
        return ridingPlanDateService.searchByCondition(tbRidingPlanDate) ;

    }

    @RequestMapping(value = "/queryById" , method = RequestMethod.POST)
    public TbRidingPlanDate queryById(@RequestBody TbRidingPlanDate tbRidingPlanDate) {
        return ridingPlanDateService.queryById(tbRidingPlanDate);
    }

}
